package com.stadyhelper.service.Impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.stadyhelper.mapper.ScoreMapper;
import com.stadyhelper.pojo.PageBean;
import com.stadyhelper.pojo.Result;
import com.stadyhelper.pojo.Score;
import com.stadyhelper.service.ScoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ScoreServiceImpl implements ScoreService {
    @Autowired
    private ScoreMapper scoreMapper;
    @Override
    public void addScore(Score score) {
        //计算总分（可复用）
        score.setScoreTotal(score.getScoreChinese() + score.getScoreMath()+score.getScoreEnglish()+score.getScorePhysics() + score.getScoreChemistry()+score.getScoreChemistry());
        scoreMapper.addScore(score);
    }

    @Override
    public PageBean<Score> listScore(Integer pageNum, Integer pageSize, String name) {
        //声明分页工具集合
        PageBean<Score> pb = new PageBean<>();
        //传入分页参数
        PageHelper.startPage(pageNum, pageSize);
        //查询所有数据
        List<Score> sc=scoreMapper.listScore(name);

        Page<Score> p= (Page<Score>) sc;
        pb.setTotal(p.getTotal());
        pb.setItems(p.getResult());
        return pb;
    }

    @Override
    public String selectNewScore() {
        Score score = scoreMapper.selectNewScore();
        String s="语文："+score.getScoreChinese()+"数学："+score.getScoreMath()+"英语："+score.getScoreEnglish()+
                "物理："+score.getScorePhysics()+"化学："+score.getScoreChemistry()+"生物："+score.getScoreBiologic();
        return s;
    }

    @Override
    public List<Score> selectForModel(Integer modelNum) {
        List<Score> s =scoreMapper.selectForModel(modelNum);
        return s;
    }

    @Override
    public void updateScore(Score score) {
        score.setScoreTotal(score.getScoreChinese() + score.getScoreMath()+score.getScoreEnglish()+score.getScorePhysics() + score.getScoreChemistry()+score.getScoreChemistry());
        scoreMapper.updateScore(score);
    }

    @Override
    public void deleteScore(Integer id) {
        scoreMapper.deleteById(id);
    }
}
